package com.ishansong.gis.tool;

/**
 * Created by danqiang on 2017/7/24.
 * 输出导数据日志
 */
class Perf {
    private long count = 0;
    private long preCount = 0;
    private long startMillis = System.currentTimeMillis();
    private long preMillis = System.currentTimeMillis();

    synchronized void out() {
        count++;
        System.out.print("count = " + count + ", ");
        long curMillis = System.currentTimeMillis();
        if ((curMillis - preMillis) / 1000 >= 3) {
            System.out.println(count);
            double elapseSeconds = (curMillis - startMillis) / 1000.0;
            double qps = count / elapseSeconds;
            System.out.println("QPS: " + qps);

            elapseSeconds = (curMillis - preMillis) / 1000.0;
            qps = (count - preCount) / elapseSeconds;
            System.out.println("QPS 3s: " + qps);

            preCount = count;
            preMillis = curMillis;
        } else {
            System.out.println("doing...");
        }
    }
}
